home *** CD-ROM | disk | FTP | other *** search
/ Complete Linux / Complete Linux.iso / docs / apps / database / ingres04.lzh / source / ctlmod / writeqry.c < prev   
Encoding:
C/C++ Source or Header  |  1985-12-18  |  2.4 KB  |  130 lines

  1. # include    <ingres.h>
  2. # include    <aux.h>
  3. # include    <tree.h>
  4. # include    <symbol.h>
  5. # include    <sccs.h>
  6.  
  7. SCCSID(@(#)writeqry.c    8.1    12/31/84)
  8.  
  9.  
  10. /*
  11. **  WRITEQRY -- write a whole query
  12. **
  13. **    An entire query is written, including range table, and so
  14. **    forth.
  15. **
  16. **    Parameters:
  17. **        root -- the root of the tree to write.
  18. **        wrfn -- the function to do the physical write.
  19. **        fnparam -- a parameter to pass to wrfn.
  20. **
  21. **    Returns:
  22. **        none
  23. **
  24. **    Side Effects:
  25. **        none.
  26. */
  27.  
  28. writeqry(root, wrfn, fnparam)
  29. QTREE    *root;
  30. int    (*wrfn)();
  31. char    *fnparam;
  32. {
  33.     register int    i;
  34.     struct srcid    sid;
  35.  
  36.     /* write the query mode */
  37.     if (Qt.qt_qmode >= 0)
  38.         writesym(QMODE, 2, (char *) &Qt.qt_qmode, wrfn, fnparam);
  39.  
  40.     /* write the range table */
  41.     for (i = 0; i < MAXRANGE; i++)
  42.     {
  43.         if (Qt.qt_rangev[i].rngvmark)
  44.         {
  45.             sid.srcvar = i;
  46.             bmove((char *) Qt.qt_rangev[i].rngvdesc, (char *) &sid.srcdesc, sizeof sid.srcdesc);
  47.             writesym(SOURCEID, sizeof sid, (char *) &sid, wrfn, fnparam);
  48.         }
  49.     }
  50.  
  51.     /* write a possible result variable */
  52.     if (Qt.qt_resvar >= 0)
  53.         writesym(RESULTVAR, 2, (char *) &Qt.qt_resvar, wrfn, fnparam);
  54.  
  55.     /* write the tree */
  56.     writetree(root, wrfn, fnparam);
  57. }
  58. /*
  59. **  WRITETREE -- write query tree
  60. **
  61. **    A query tree is written to the down pipe.  The parameter is
  62. **    the root of the tree to be written.
  63. **
  64. **    Parameters:
  65. **        q1 -- the root of the tree to write.
  66. **        wrfn -- the function to call to do physical
  67. **            writes.
  68. **        fnparam -- a parameter to pass to wrfn.
  69. **
  70. **    Returns:
  71. **        none
  72. **
  73. **    Side Effects:
  74. **        none
  75. */
  76.  
  77. writetree(q1, wrfn, fnparam)
  78. QTREE    *q1;
  79. int    (*wrfn)();
  80. char    *fnparam;
  81. {
  82.     register QTREE    *q;
  83.     register int    l;
  84.     register char    t;
  85.  
  86.     q = q1;
  87.  
  88.     /* write the subtrees */
  89.     if (q->left != NULL)
  90.         writetree(q->left, wrfn, fnparam);
  91.     if (q->right != NULL)
  92.         writetree(q->right, wrfn, fnparam);
  93.  
  94.     /* write this node */
  95.     t = q->sym.type;
  96.     if (t == AND || t == ROOT || t == AGHEAD)
  97.         q->sym.len = 0;
  98.     l = q->sym.len & I1MASK;
  99.     writesym(q->sym.type, l, (char *) &q->sym.value, wrfn, fnparam);
  100. #    ifdef    xQTR1
  101.     if (tTf(11, 8))
  102.         nodepr(q);
  103. #    endif
  104. }
  105. /*
  106. **  WRITESYM -- write a symbol block
  107. **
  108. **    A single symbol entry of the is written.
  109. **    a 'value' of zero will not be written.
  110. */
  111.  
  112. writesym(typ, len, value, wrfn, fnparam)
  113. int    typ;
  114. int    len;
  115. char    *value;
  116. int    (*wrfn)();
  117. char    *fnparam;
  118. {
  119.     struct symbol    sym;
  120.     register char    *v;
  121.     register int    l;
  122.  
  123.     sym.type = typ & I1MASK;
  124.     sym.len = l = len & I1MASK;
  125.     (*wrfn)(&sym, 2, fnparam);
  126.     v = value;
  127.     if (v != NULL && l > 0)
  128.         (*wrfn)(v, l, fnparam);
  129. }
  130.